﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Effects.Wave
{
    /// <summary>
    ///  Representation of complex number.
    /// </summary>
    public struct Complex
    {
        /// <summary>
        ///  Real part.
        /// </summary>
        public double re;

        /// <summary>
        ///  Imaginary part.
        /// </summary>
        public double im;

        /// <summary>
        ///  Creates new complex number with given real and imaginary part.
        /// </summary>
        /// <param name="re"> Real part of a complex number </param>
        /// <param name="im"> Imaginary part of a complex number </param>
        public Complex(double re, double im)
        {
            this.re = re;
            this.im = im;
        }

        #region operations
        // addition, subtraction and multiplication operators

        /// <summary>
        ///  Addition of two complex numbers.
        /// </summary>
        /// <param name="c1"> complex number </param>
        /// <param name="c2"> complex number </param>
        /// <returns> addition of c1 and c2 (c1 + c2)</returns>
        public static Complex operator + (Complex c1,Complex c2)
        {
            return new Complex(c1.re + c2.re, c1.im + c2.im);
        }

        /// <summary>
        ///  Subtraciotn of two complex numbers.
        /// </summary>
        /// <param name="c1"> complex number </param>
        /// <param name="c2"> complex number </param>
        /// <returns> substraciotn of c1 and c2 (c1 - c2)</returns>
        public static Complex operator -(Complex c1, Complex c2)
        {
            return new Complex(c1.re - c2.re, c1.im - c2.im);
        }

        /// <summary>
        ///  Multiplication of two complex numbers
        /// </summary>
        /// <param name="c1"> complex number</param>
        /// <param name="c2"> complex number</param>
        /// <returns> multiplication of c1 and c2 (c1 * c2)</returns>
        public static Complex operator *(Complex c1, Complex c2)
        {
            return new Complex(c1.re*c2.re - c1.im*c2.im , c1.re*c2.im + c1.im*c2.re);
        }


        #endregion

        #region conjugate
        // Conjugate value of complex number

        /// <summary>
        ///  Conjugate of a complex number
        /// </summary>
        /// <returns>
        ///  returns conjugate complex number to the one it is called on.
        /// </returns>
        public Complex conjugate()
        {
            return new Complex(this.re, -this.im);
        }

        #endregion
    }
}